home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / programming / c / icu-1.3.1 / icu-bin / include / schriter.h < prev    next >
C/C++ Source or Header  |  2000-02-23  |  7KB  |  178 lines

  1. /*
  2. *******************************************************************************
  3. *                                                                             *
  4. * COPYRIGHT:                                                                  *
  5. *   (C) Copyright International Business Machines Corporation, 1998-1999      *
  6. *   Licensed Material - Program-Property of IBM - All Rights Reserved.        *
  7. *   US Government Users Restricted Rights - Use, duplication, or disclosure   *
  8. *   restricted by GSA ADP Schedule Contract with IBM Corp.                    *
  9. *                                                                             *
  10. *******************************************************************************
  11. *
  12. * File schriter.h
  13. *
  14. * Modification History:
  15. *
  16. *   Date        Name        Description
  17. *  05/05/99     stephen     Cleaned up.
  18. *******************************************************************************
  19. */
  20.  
  21. #ifndef SCHRITER_H
  22. #define SCHRITER_H
  23.  
  24. #include "utypes.h"
  25. #include "chariter.h"
  26.  
  27. /**
  28.  * A concrete subclass of CharacterIterator that iterates over the
  29.  * characters in a UnicodeString.  It's possible not only to create an
  30.  * iterator that iterates over an entire UnicodeString, but also to
  31.  * create only that iterates over only a subrange of a UnicodeString
  32.  * (iterators over different subranges of the same UnicodeString don't
  33.  * compare equal).  */
  34. class U_COMMON_API StringCharacterIterator : public CharacterIterator {
  35. public:
  36.   /**
  37.    * Create an iterator over the UnicodeString referred to by "text".
  38.    * The iteration range is the whole string, and the starting position is 0.
  39.    */
  40.   StringCharacterIterator(const UnicodeString& text);
  41.  
  42.   /**
  43.    * Create an iterator over the UnicodeString referred to by "text".
  44.    * The iteration range is the whole string, and the starting
  45.    * position is specified by "pos".  If "pos" is outside the valid
  46.    * iteration range, the behavior of this object is undefined.  */
  47.   StringCharacterIterator(const UnicodeString&    text,
  48.               UTextOffset              pos);
  49.  
  50.   /**
  51.    * Create an iterator over the UnicodeString referred to by "text".
  52.    * The iteration range begins with the character specified by
  53.    * "begin" and ends with the character BEFORE the character specfied
  54.    * by "end".  The starting position is specified by "pos".  If
  55.    * "begin" and "end" don't form a valid range on "text" (i.e., begin
  56.    * >= end or either is negative or greater than text.size()), or
  57.    * "pos" is outside the range defined by "begin" and "end", the
  58.    * behavior of this iterator is undefined.  */
  59.   StringCharacterIterator(const UnicodeString&    text,
  60.               UTextOffset              begin,
  61.               UTextOffset              end,
  62.               UTextOffset              pos);
  63.  
  64.   /**
  65.    * Copy constructor.  The new iterator iterates over the same range
  66.    * of the same string as "that", and its initial position is the
  67.    * same as "that"'s current position.  */
  68.   StringCharacterIterator(const StringCharacterIterator&  that);
  69.  
  70.   /**
  71.    * Destructor.  */
  72.   virtual ~StringCharacterIterator();
  73.  
  74.   /**
  75.    * Assignment operator.  *this is altered to iterate over the sane
  76.    * range of the same string as "that", and refers to the same
  77.    * character within that string as "that" does.  */
  78.   StringCharacterIterator&
  79.   operator=(const StringCharacterIterator&    that);
  80.  
  81.   /**
  82.    * Returns true if the iterators iterate over the same range of the
  83.    * same string and are pointing at the same character.  */
  84.   virtual bool_t          operator==(const CharacterIterator& that) const;
  85.  
  86.   /**
  87.    * Generates a hash code for this iterator.  */
  88.   virtual int32_t         hashCode(void) const;
  89.  
  90.   /**
  91.    * Returns a new StringCharacterIterator referring to the same
  92.    * character in the same range of the same string as this one.  The
  93.    * caller must delete the new iterator.  */
  94.   virtual CharacterIterator* clone(void) const;
  95.                                 
  96.   /**
  97.    * Sets the iterator to refer to the first character in its
  98.    * iteration range, and returns that character, */
  99.   virtual UChar         first(void);
  100.  
  101.   /**
  102.    * Sets the iterator to refer to the last character in its iteration
  103.    * range, and returns that character.  */
  104.   virtual UChar         last(void);
  105.  
  106.   /**
  107.    * Sets the iterator to refer to the "position"-th character in the
  108.    * UnicodeString the iterator refers to, and returns that character.
  109.    * If the index is outside the iterator's iteration range, the
  110.    * behavior of the iterator is undefined.  */
  111.   virtual UChar         setIndex(UTextOffset pos);
  112.  
  113.   /**
  114.    * Returns the character the iterator currently refers to.  */
  115.   virtual UChar         current(void) const;
  116.  
  117.   /**
  118.    * Advances to the next character in the iteration range (toward
  119.    * last()), and returns that character.  If there are no more
  120.    * characters to return, returns DONE.  */
  121.   virtual UChar         next(void);
  122.  
  123.   /**
  124.    * Advances to the previous character in the iteration rance (toward
  125.    * first()), and returns that character.  If there are no more
  126.    * characters to return, returns DONE.  */
  127.   virtual UChar         previous(void);
  128.  
  129.   /**
  130.    * Returns the numeric index of the first character in this
  131.    * iterator's iteration range.  */
  132.   virtual UTextOffset      startIndex(void) const;
  133.  
  134.   /**
  135.    * Returns the numeric index of the character immediately BEYOND the
  136.    * last character in this iterator's iteration range.  */
  137.   virtual UTextOffset      endIndex(void) const;
  138.  
  139.   /**
  140.    * Returns the numeric index in the underlying UnicodeString of the
  141.    * character the iterator currently refers to (i.e., the character
  142.    * returned by current()).  */
  143.   virtual UTextOffset      getIndex(void) const;
  144.  
  145.   /**
  146.    * Copies the UnicodeString under iteration into the UnicodeString
  147.    * referred to by "result".  Even if this iterator iterates across
  148.    * only a part of this string, the whole string is copied.  @param
  149.    * result Receives a copy of the text under iteration.  */
  150.   virtual void            getText(UnicodeString& result);
  151.  
  152.   /**
  153.    * Return a class ID for this object (not really public) */
  154.   virtual UClassID         getDynamicClassID(void) const 
  155.     { return getStaticClassID(); }
  156.  
  157.   /**
  158.    * Return a class ID for this class (not really public) */
  159.   static UClassID          getStaticClassID(void) 
  160.     { return (UClassID)(&fgClassID); }
  161.  
  162. private:
  163.   StringCharacterIterator();
  164.         
  165.   UnicodeString            text;
  166.   UTextOffset              pos;
  167.   UTextOffset              begin;
  168.   UTextOffset              end;
  169.  
  170.   static UClassID           fgClassID;
  171. };
  172.  
  173. #endif
  174.  
  175.  
  176.  
  177.  
  178.